package com.example.commontest.service.Impl;

import com.example.commontest.service.AsyncService;
import com.example.commontest.service.ServiceTest;
import com.example.commontest.service.SynchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;

/**
 * @Author huaiyu yin
 * @Date 2021/5/24 12:15 下午
 * @Version 1.0
 */
@Service
public class ServiceTestImpl implements ServiceTest {
    @Autowired
    private AsyncService asyncService;
    @Autowired
    private SynchService synchService;


    @Override
    public void test(Integer times) {
        long s = System.currentTimeMillis();
        //计数
        CountDownLatch latch = new CountDownLatch(2);
        Future<Integer> atention = asyncService.getAtention(times,latch);
        Future<Integer> followed = asyncService.getFollowed(times, latch);
        long e = System.currentTimeMillis();
        System.out.println("asyncService spend: " + (e - s));
        s = System.currentTimeMillis();
        Integer atention1 = synchService.getAtention(times);
        Integer followed1 = synchService.getFollowed(times);
        e = System.currentTimeMillis();
        System.out.println("synchService spend: " + (e - s));
    }
}
